package com.cn.dao;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.cn.entity.Department;


/*
 * 科类数据操作
 */
public class DepartmentDao extends BaseDao {

	/**
	 * 
	 * @param department 部门对象
	 * @return 
	 */
	 
	public int  saveDepartment(Department department) {
		int count =0;
			con = this.getCon();
			 String sql ="insert into Department values(?,?)";
			try {
				psta = con.prepareStatement(sql);
				psta.setString(1,department.getName());
				psta.setString(2,department.getTypes());
				count = psta.executeUpdate();
			} catch (Exception e) {
				e.printStackTrace();
			}finally{
				this.closeAll();
			}
			
			return count;
		}
	
	/**
	 * 查询相应部门信息标题
	 * @return 返回所有部门集合
	 */
	public List findListDepartment(String types) {
		List list = new ArrayList();
		
		con = this.getCon();
		String sql ="select * from department where types="+types;
		try {
			psta = con.prepareStatement(sql);
			rst = psta.executeQuery();
			while (rst.next()) {
				Department department =new Department();
				department.setId(rst.getInt("id"));
				department.setName(rst.getString("name"));
				department.setTypes(rst.getString("types"));
				list.add(department);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			this.closeAll();
		}
		
		return list;
	}
	/**
	 * 测试
	 * @param args
	 */
	public static void main(String[] args) {
		DepartmentDao dt=new DepartmentDao();
		List listDt=dt.findListDepartment("0");
		System.out.println("数据库有:"+listDt.size());
	}

}
